package com.lxyk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.lxyk.mapper.CustomerMapper;
import com.lxyk.pojo.Customer;
import com.lxyk.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;


    @Override
    public List<Customer> listCustomer() {
        return customerMapper.selectList(null);
    }

    @Override
    public int saveCustomer(Customer customer) {
        return customerMapper.insert(customer);
    }

    @Override
    public int deleteCustomerById(Integer cid) {
        QueryWrapper<Customer>qw=new QueryWrapper<>();//这里也可以不用条件构造器 直接用deleteById
        qw.eq("cid",cid);
        return customerMapper.delete(qw);
    }

    @Override
    public Customer getCustomerById(Integer cid) {
        QueryWrapper<Customer> qw = new QueryWrapper<>();
        qw.eq("cid",cid);
        return customerMapper.selectOne(qw);
    }

    @Override
    public int updateCustomer(Customer customer) {
        QueryWrapper<Customer> qw = new QueryWrapper<>();
        qw.eq("cid",customer.getCid());
        return customerMapper.update(customer,qw);
    }

    @Override
    public PageInfo<Customer> listCust(Customer customer, Integer pageNum, Integer pageSize) {
        List<Customer> customers = customerMapper.listCustomer(customer);
        return new PageInfo<>(customers);
    }
}
